# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=tls-map
pkgver=v3.1.0.r41.g47f7267
pkgrel=1
pkgdesc='CLI & library for TLS cipher suites manipulation.'
arch=('any')
groups=('blackarch' 'blackarch-crypto' 'blackarch-misc')
url='https://noraj.github.io/tls-map/'
license=('MIT')
depends=('ruby' 'ruby-paint' 'ruby-docopt' 'ruby-rexml' 'ruby-csv')
makedepends=('git')
options=(!emptydirs)
source=("git+https://github.com/noraj/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd $pkgname

  # waiting for an AL update https://archlinux.org/packages/extra/any/ruby-csv/
  sed -i "s/'csv', '~> 3.3'/'csv', '~> 3.2'/" Gemfile tls-map.gemspec
}

build() {
  cd $pkgname

  gem build "$pkgname.gemspec"
}

package() {
  cd $pkgname

  _gemdir="$(ruby -e'puts Gem.default_dir')"
  _release=$(gem build "$pkgname.gemspec" | grep Version | cut -d' ' -f4)

  gem install --ignore-dependencies --no-user-install --no-document \
    -i "$pkgdir/$_gemdir" -n "$pkgdir/usr/bin" "$pkgname-$_release.gem"

  rm -f "$pkgdir/$_gemdir/cache/$pkgname-$_release.gem"
  find "$pkgdir/$_gemdir/extensions/" -name *.so -delete
  rm -rf "$pkgdir/$_gemdir/gems/$pkgname-$_release/{test,.github}"

  install -Dm 644 "$pkgdir/$_gemdir/gems/$pkgname-$_release/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

